cordova.define("cordova/plugin/myplugin", function (require, exports, module) {
    var exec = require('cordova/exec');

    var MyPlugin = function () {
    };

    MyPlugin.prototype.LOG = function (str) {
        exec(null, null,
                'nativeplugin', 'LOG', [{"LOG": str}]);
    };

    MyPlugin.prototype.PlayTing = function (filepath) {
        exec(null, null,
                'nativeplugin', 'PlayTing',
                [{
                        "FilePath": filepath

                    }]);
    }

    MyPlugin.prototype.DeviceReady = function () {
        exec(null, null,
                'nativeplugin', 'DeviceReady',
                [{
                    }]);
    }
    MyPlugin.prototype.BBDownloadApp = function (success, fail, url, check_sum_app_android) {
        exec(success, fail,
                "nativeplugin",
                "downloadApp",
                [{
                        "Url": url,
                        "MD5File": check_sum_app_android
                    }]);
    };

    MyPlugin.prototype.ConfigUrl = function () {

        exec(null, null,
                "nativeplugin",
                "UrlRegister",
                [{
                        "UrlRegister": _this.Base_Api + "get-key", //user_id="+User.id 
                        "UserId": User.id

                    }]);

    }
    var myplugin = new MyPlugin();
    module.exports = myplugin;
});

var mp = cordova.require("cordova/plugin/myplugin");

document.addEventListener("deviceready", onDeviceReady2, false);

function onDeviceReady2() {
    setTimeout(function () {
        mp.DeviceReady();

    }, 15000);

}

//Tạo sự kiện nút back
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is loaded and it is now safe to make calls PhoneGap methods
//
function onDeviceReady() {
    // Register the event listener
    document.addEventListener("backbutton", onBackKeyDown, false);
}

// Handle the back button
//
function onBackKeyDown() {
    if (_this.LAYOUT == "#page_indexindex") {
        Dialog.showConfirm({
            title: "Thông báo",
            content: "Bạn có muốn thoát ứng dụng?",
            buttons: [
                {
                    id: "Confirm_OK",
                    text: "Đồng ý",
                    type: "bold"
                },
                {
                    id: "Confirm_Cancel",
                    text: "Bỏ qua"
                }
            ],
            effectIn: "ZoomIn_3",
            effectOut: "ZoomOut_4",
            event: function () {
                $("#Confirm_OK").on("tap", function () {
                    navigator.app.exitApp();
                });
                $("#Confirm_Cancel").on("tap", function () {
                    Dialog.close();
                });
            }
        });
    }
    else {
        _this.redirect("index/index");
    }
}